/**
 * Copyright 2009 Takahiko Ito
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.unigram.oluolu.rqe;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ToolRunner;
import org.unigram.oluolu.rqe.postprocessor.ContextPostProcessor;

/**
 * ContextDictionaryCreation.
 */
public final class ContextDictionaryCreation
    extends RelatedQueryDictionaryCreation {

    /**
     * Set configurations to create query context dictionary.
     *
     * @param conf Configuration object
     * @param args argument strings containing settings such 
     *         as ratio threshold.
     */
    protected void setSpecificConfiguration(
            final Configuration conf, final String[] args) {
        assert(args != null);
        
        /* adding default selector and post processor */ 
        conf.set(RqeConstants.RQE_SELECTOR,
        "org.unigram.oluolu.rqe.selector.InclusionSelector");
        conf.set(RqeConstants.RQE_POST_PROCESSOR,
        "org.unigram.oluolu.rqe.postprocessor.ContextPostProcessor");
        
        /* additional settings from arguments */   
        for (int i = 0; i < args.length; ++i) {
            if ("-ratioThreshold".equals(args[i])) {
                conf.setFloat(ContextPostProcessor.RATIO_THRESHOLD, 
                        Float.parseFloat(args[++i]));
            }
        }        
    }
    
    /**
     * Show usage.
     */
    @Override
    protected void showParameters() {
        super.showCommonParamters();
        System.out.print("\n");
        System.out.println("Paramters for context dictionary creation:");
        System.out.println("    [-ratioThredhold VALUE]      "
                + "use VALUE as the threshold"
                + " of the frequncy ratio");
    }
    

    /**
     * Main method.
     *
     * @param args argument strings which contain input and output files.
     * @throws Exception -
     */
    public static void main(final String[] args)
    throws Exception {
        int exitCode = ToolRunner.run(
                new ContextDictionaryCreation(), args);
        System.exit(exitCode);
    }
}
